package com.bac.rentmap.web.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Workaround for static resources. TODO: remove it after next GAE release
 * 
 * @author Andrew Osipenko
 * @deprecated
 */
public class StaticResourceServlet extends HttpServlet {
	private static final Logger log = Logger
			.getLogger(StaticResourceServlet.class.getName());

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String uri = request.getRequestURI();
		log.fine("URI: " + uri);
		InputStream inputStream = getServletContext().getResourceAsStream(uri);
		int b;
		OutputStream outputStream = response.getOutputStream();
		while ((b = inputStream.read()) != -1) {
			outputStream.write(b);
		}
		outputStream.close();
	}
}
